package org.example.yunshu.demos.config;

import lombok.extern.slf4j.Slf4j;
import org.example.yunshu.demos.model.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@Slf4j
@ResponseBody
@ControllerAdvice
public class ErrorHandler {
//    捕获异常,返回统一结果
    @ExceptionHandler
    public Result handler(Exception e){
        log.error("发生异常: ",e);
        return Result.error("发生错误,请联系管理员");
    }
    @ExceptionHandler
    public Result handler(NullPointerException e){
        log.error("发生空指针异常: ",e);
        return Result.error("发生空指针异常");
    }

}
